package com.loveyukari.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.loveyukari.support.JsonResult;
import com.loveyukari.utils.FanyiUtils;

import net.sf.json.JSONObject;

/**
*
*yangshaohua
*2017年8月15日下午2:31:59
**/
@RequestMapping("/admin/fanyi")
@Controller
public class FanyiController {
	
	private Logger log = LoggerFactory.getLogger(FanyiController.class);

	@RequestMapping("/enToZh")
	@ResponseBody
	public JsonResult<Object> enToZh(String txt){
		JSONObject jsonObject = FanyiUtils.translate(txt.toLowerCase());
		if (jsonObject.containsKey("word_name")){
			try {
				JSONObject symbols = jsonObject.optJSONArray("symbols").getJSONObject(0);
				String phEn = symbols.optString("ph_en");
				String phAm = symbols.optString("ph_am");
				String result = "【美】"+phAm+"  【英】"+phEn;
				return new JsonResult<Object>(0,"",result);
			} catch (Exception e) {
				log.error(e.getMessage(),e);
				return new JsonResult<Object>(-1,"出错啦!快找小马!");
			}
		} else {
			return new JsonResult<Object>(-1,"该单词不存在");
		}
	}
	
}
